import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Serializer = require('./../base/Serializer');
import ObjPosition=require('./../base/ObjPosition');
import SJGReplaceItemBase = require('./SJGReplaceItemBase');
import CompoundPath = require('./../../common/graph/CompoundPath');
import CommonModel = require('./../../common/model/CommonModel');



var CONFIG=require('../../../../common/config');
export  = SJGReplaceItemImage;

/**
 *
 * @author 
 *
 */
class SJGReplaceItemImage extends SJGReplaceItemBase{
    public value: string="";   //  图片地址
    public pos: ObjPosition=new ObjPosition(); // 图片大小、位置等信息
    public mask: CompoundPath = null; // 图片蒙板
    
    public constructor(g?) {
        super(g);

        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemImage;
        this.type=SJGReplaceItemBase.TYPE_IMAGE;
    }
    
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj,versionId) {
        super.fromJson(jsonObj,versionId);

        this.value = jsonObj.value;
        if(jsonObj.hasOwnProperty("pos")){
            this.pos.fromJson(jsonObj.pos,versionId);    
        }
        
        if(jsonObj.hasOwnProperty("mask") && jsonObj.mask != null) {
            this.mask = new CompoundPath();
            this.mask.fromJson(jsonObj.mask,versionId);
        }
    }
    
    // 转成json字符串
    public toJson(): string {
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length - 2);

        var ret = '{';
        ret += superJson;
        
        // value
        ret += ',';
        ret += '"value":' + '"';
        ret += this.value + '"';
        
        // pos
        ret+=',';
        ret+='"pos":';
        ret+=this.pos.toJson();
        
        // mask
        if(this.mask != null) {
            ret += ',';
            ret += '"mask":';
            ret += this.mask.toJson();
        }

        ret += '}';
        return ret;
    }
    // 获取对象名称
    public getObjetName(): string {
        return "图片";
    }

    
    //SJG_MARK_APPEND--------------------
    public isContentEmpty():boolean {
        return this.value==null || this.value.length==0;
    }

}//SJG_MARK_END-------------------------